package com.baichen.spring.web;

import com.baichen.spring.Component;

@Component
@Controller
@RequestMapping("/hello")
public class HelloController {

    @RequestMapping("/a")
    public String hello() {
        return "Hello, World!";
    }

    @RequestMapping("/json")
    @RequestBody
    public User json(@Param("name") String name, @Param("age") Integer age) {
        User user = new User();
        user.setName(name);
        user.setAge(age);
        return user;
    }

    @RequestMapping("/view")
    public ModelAndView view(@Param("name") String name, @Param("age") Integer age) {
        ModelAndView modelAndView = new ModelAndView();
        modelAndView.setView("index.html");
        modelAndView.getContext().put("name", name);
        modelAndView.getContext().put("age", String.valueOf(age));
        return modelAndView;
    }
}
